#!/usr/bin/env bash

# Copyright 2014, Joyent Inc. All rights reserved
# Explicitly set hostid.

# load common functions and vars
. /lib/smartdc/lib_smartdc_scripts.cfg

lib_smartdc_info "Start of $(basename $0) script"

# ** This script must be run once at provision via firstboot **
# Without this, /usr/bin/hostid will always return 00000000 under the Joyent
# KVM virutalized environement (see IMAGE-441)
printf $($MDATA_GET_BIN sdc:uuid | awk \
  '{ print substr($0,7,2)substr($0,5,2)substr($0,3,2)substr($0,1,2) }' | \
    sed 's/../\\x&/g') > /etc/hostid

lib_smartdc_info "/etc/hostid created"
